package algorithmTopics.devise;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class Solution {


    // 保存原来的数组
    private int[] nums;

    public Solution(int[] nums) {
        this.nums = nums;
    }

    public int[] reset() {
        return nums;
    }


    @Override
    public String toString() {
        return "Solution{" +
                "nums=" + Arrays.toString(nums) +
                '}';
    }

    public int[] shuffle() {
        int len = nums.length;
        int[] ints = new int[len];
        //公式：Math.random()*(n-m)+m，生成大于等于m小于n的随机数；
        HashMap<Integer, Integer> index = new HashMap<>();
        for (int i = 0; i < len;) {
            int a = (int) (Math.random()*len);
            if (index.get(a) == null) {
                ints[a] = nums[i];
                index.put(a,1);
                i++;
            }
        }
        return ints;
    }
}
